package com.douqu.game.core.util;

import com.douqu.game.core.config.sprite.MasterConfig;
import com.douqu.game.core.controller.PlayerController;
import com.douqu.game.core.e.E_Attribute;
import com.douqu.game.core.entity.ChangeGoods;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.battle.BattleTemp;
import com.douqu.game.core.entity.db.CardDB;
import com.douqu.game.core.entity.ext.data.challenge.HegemonyScoreChangeBean;
import com.douqu.game.core.entity.world.map.*;
import com.douqu.game.core.factory.ConfigFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.WorldInfoFactory;
import com.douqu.game.core.protobuf.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;

import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by bean
 * 2017-03-24 15:54.
 */
public class SendUtils {


    public static void sendMsg(Channel channel, int msgID, byte[]... data)
    {
        byte[] sendData = data == null || data.length == 0 ? null : data[0];

        ByteBuf byteBuf = Unpooled.buffer();
        int length = sendData == null ? 0 : sendData.length;
        if(ByteOrder.nativeOrder().toString().equals(ByteOrder.LITTLE_ENDIAN.toString())){
            byteBuf.writeIntLE(length);//总包长
            byteBuf.writeShortLE(msgID);//长度为2
        }else{
            byteBuf.writeInt(length);//总包长
            byteBuf.writeShort(msgID);//长度为2
        }
        if(sendData != null)
            byteBuf.writeBytes(sendData);


        channel.writeAndFlush(byteBuf);
    }



    public static SGCommonProto.FlushData createFlushData(SGCommonProto.E_GOODS_TYPE type, int id, int change, int curValue, String uniqueId, long endTime, int index)
    {
        SGCommonProto.FlushData.Builder flushData = SGCommonProto.FlushData.newBuilder();
        flushData.setIndex(index);
        flushData.setType(type);
        flushData.setId(id);
        flushData.setChange(change);
        flushData.setCurValue(curValue);
        flushData.setUniqueId(StringUtils.isNullOrEmpty(uniqueId) ? "" : uniqueId);
        flushData.setEndTime(endTime);
        return flushData.build();
    }


    public static void mailPush(SGCommonProto.E_MAIL_TYPE type ,PlayerController playerController)
    {
        SGPlayerProto.S2C_MailNewMailNotify.Builder builder = SGPlayerProto.S2C_MailNewMailNotify.newBuilder();
        builder.setMailType(type);
        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Mail_NewMailNotify_VALUE, builder.build().toByteArray());
        List<SGCommonProto.E_RED_POINT_TYPE> types = new ArrayList<>();
        types.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_EMAIL);
        sendRedPointRemind(playerController, types);
    }

    public static void taskPush(int taskId,PlayerController playerController){
        SGTaskProto.S2C_TaskMainDoneNotify.Builder builder = SGTaskProto.S2C_TaskMainDoneNotify.newBuilder();
        builder.setTaskId(taskId);
        builder.setStatus(SGCommonProto.E_TASK_STATUS.TASK_STATUS_UNCLAIMED);
        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Task_TaskMainDoneNotify_VALUE, builder.build().toByteArray());
    }


    /**
     * 推送获得的物品
     * @param playerController
     */
    public static void sendChangeData(int code, PlayerController playerController)
    {
        ChangeGoods changeGoods = playerController.getPlayer().getChangeGoods();
        if(changeGoods.getShowList().size() > 0 || changeGoods.getOtherList().size() > 0)
        {
            SGPlayerProto.S2C_FlushData.Builder flushDataRes = SGPlayerProto.S2C_FlushData.newBuilder();
            flushDataRes.setMsgId(SGMainProto.E_MSG_ID.forNumber(code));
            flushDataRes.addAllShowData(changeGoods.getShowList());
            flushDataRes.addAllOtherData(changeGoods.getOtherList());
            flushDataRes.setCurrentServerTime((int) (DataFactory.currentTime / 1000));

            LogUtils.debug("sendFlushData--->>" + flushDataRes);

            playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Player_FlushData_VALUE, flushDataRes.build().toByteArray());

            changeGoods.clearGoodsList();
        }
    }

    /*public static void sendFunctionData( PlayerController playerController)
    {
        ChangeGoods changeGoods = playerController.getPlayer().getChangeGoods();
        if(!changeGoods.getFunctionList().isEmpty())
        {
            // 发送模块开启信息
            for(int functionId : changeGoods.getFunctionList()){
                SGPlayerProto.S2C_FunctionOpening.Builder b = SGPlayerProto.S2C_FunctionOpening.newBuilder();
                b.setFunctionId(functionId);

                playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Function_Open_VALUE, b.build().toByteArray());
            }
            // 清空
            playerController.getPlayer().getChangeGoods().clearFunctionList();
        }
    }*/



    public static void sendRedPointRemind(PlayerController playerController, SGCommonProto.E_RED_POINT_TYPE type) {
        SGPlayerProto.S2C_RedPointRemind.Builder response = SGPlayerProto.S2C_RedPointRemind.newBuilder();
        if (type != null ) {
            response.addTypes(type);
            LogUtils.debug("发送红点：" + type.toString());
            playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Player_RedPointRemind_VALUE, response.build().toByteArray());
        }
    }

    public static void sendRedPointRemind(PlayerController playerController, List<SGCommonProto.E_RED_POINT_TYPE> types){
        SGPlayerProto.S2C_RedPointRemind.Builder response = SGPlayerProto.S2C_RedPointRemind.newBuilder();
        if(types != null && types.size() > 0){
            response.addAllTypes(types);
            LogUtils.debug("发送红点：" + types.toString());
            playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_Player_RedPointRemind_VALUE, response.build().toByteArray());
        }
    }

    public static void sendEnterWorldMap(SpritePlayerBean spritePlayerBean, WorldMapData worldMapData)
    {
        SGMapProto.S2C_EnterWorldMap.Builder response = SGMapProto.S2C_EnterWorldMap.newBuilder();
        response.setFlag(true);
        response.setCurCity(spritePlayerBean.getCurCity());
        response.addAllCityItem(worldMapData.parseList());
        response.addAllRoute(spritePlayerBean.getRouteList());
        response.setArmyStatus(spritePlayerBean.getStatus());

        spritePlayerBean.getPlayerController().sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_Enter_VALUE, response.build().toByteArray());
    }


    /**
     * 通知队伍状态
     * @param playerController
     * @param status
     */
    public static void sendMapArmyStatus(PlayerController playerController, SGCommonProto.E_ARMY_STATUS status)
    {
        if(playerController == null)
            return;

        LogUtils.debug("通知状态 -> :" + status + " 玩家:" + playerController.getName());

        SGMapProto.S2C_ArmyStatus.Builder response = SGMapProto.S2C_ArmyStatus.newBuilder();
        response.setStatus(status);
        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_ArmyStatus_VALUE, response.build().toByteArray());
    }

    public static SGCommonProto.ChatItem createChatItem(String nickName, String content, SGCommonProto.E_CHAT_TYPE chatType)
    {
        SGCommonProto.ChatItem.Builder chatItem = SGCommonProto.ChatItem.newBuilder();
        chatItem.setNickName(nickName);
        chatItem.setChatType(chatType);
        chatItem.setContent(content);
        chatItem.setSendTime(DataFactory.currentTime);

        return chatItem.build();
    }

    public static void sendHegemonyResult(PlayerController playerController,Map<SGCommonProto.E_MAPINTEGRAL_SETTLE_TYPE,SGCommonProto.HegemonyResultItem.Builder> items,
            int totalScore,int vipPlus,int campScore,boolean isBig){
        if (playerController == null){
            LogUtils.warn("sendHegemonyResult playerController is null");
            return;
        }
        SGMapProto.S2C_MapHegemonyResult.Builder response = SGMapProto.S2C_MapHegemonyResult.newBuilder();
        for (SGCommonProto.E_MAPINTEGRAL_SETTLE_TYPE itemType:SGCommonProto.E_MAPINTEGRAL_SETTLE_TYPE.values()){
            if (itemType != SGCommonProto.E_MAPINTEGRAL_SETTLE_TYPE.UNRECOGNIZED
                    && itemType != SGCommonProto.E_MAPINTEGRAL_SETTLE_TYPE.WORLD_MAP_INTEGRAL_SETTLE_UNKNOWN){
                if (items.get(itemType) != null){
                    response.addItems(items.get(itemType));
                }
            }
        }
        response.setIsBig(isBig);
        response.setCampAddition(campScore);
        response.setVipAddition(vipPlus);
        response.setTotalIntegral(totalScore);
        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_HegemonyResult_VALUE,response.build().toByteArray());
    }

    /**
     * 通知分数变化
     * @param playerController
     */
    public static void sendHegemoneyChange(PlayerController playerController,HegemonyScoreChangeBean... changeBean){
        if (changeBean == null || changeBean.length == 0)
            return;

        SGMapProto.S2C_HegemontScoreChange.Builder builder;
        for (HegemonyScoreChangeBean bean:changeBean){
            builder = SGMapProto.S2C_HegemontScoreChange.newBuilder();
            builder.setType(SGCommonProto.E_MAPINTEGRAL_SETTLE_TYPE.forNumber(bean.getType()));
            builder.setValue(bean.getValue());
            builder.setScore(bean.getScore());
            builder.setChangeScore(bean.getChangeScore());
            if (playerController == null){
                LogUtils.error("sendHegemonyChange playerController is null");
                return;
            }
            playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_HegemontScoreChange_VALUE, builder.build().toByteArray());
        }
    }


    public static void sendCityStatus(CityBean cityBean, SGCommonProto.E_CITY_STATUS beforeStatus)
    {
//        if (cityBeans.length == 0)
//            return;

        SGMapProto.S2C_ChangeCityState.Builder response = SGMapProto.S2C_ChangeCityState.newBuilder();
//        for (CityBean cityBean : cityBeans)
//        {
            response.addCityItem(cityBean.parse());

            cityBean.sendDetailInfo(beforeStatus);
//        }

//        LogUtils.debug("发送城的状态改变 -> " + response);

        WorldInfoFactory.getInstance().getWorldMapData(cityBean.getMasterPlayerIndex()).dispatchMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_ChangeCityState_VALUE, response.build().toByteArray());
    }

    /**
     * 离开城的时候因为玩家还没有加入到任何一个城里，所以只能单独发送城状态信息
     * @param spritePlayerBean
     */
    public static void sendCityStatus(CityBean cityBean, SpriteBean spritePlayerBean)
    {
        SGMapProto.S2C_ChangeCityState.Builder response = SGMapProto.S2C_ChangeCityState.newBuilder();
        response.addCityItem(cityBean.parse());
        spritePlayerBean.sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_ChangeCityState_VALUE, response.build().toByteArray());
    }


    /**
     * 发送城详情
     *
     * @param reqType
     * @param team
     * @param cityBean
     * @param isSelf
     * @param isAttacker
     * @param showQueue
     * @param notifyLookPlayer  是否通知正在查看这个城的玩家
     * @param playerControllers
     */
    public static void sendCityDetailInfo(SGCommonProto.E_ARMY_STATUS reqType, SGCommonProto.E_ARMY_TEAM team, CityBean cityBean, boolean isSelf, boolean isAttacker, boolean showQueue, boolean notifyLookPlayer, Object... playerControllers)
    {
        if(playerControllers.length == 0 && !notifyLookPlayer)
            return;

        if(playerControllers.length == 0 && notifyLookPlayer && cityBean.getLookSpriteBeanList().isEmpty())
            return;

        for (Object o : playerControllers) {
            if (!(o instanceof PlayerController))
                return;
        }

        SGMapProto.S2C_CityDetailInfo.Builder response = SGMapProto.S2C_CityDetailInfo.newBuilder();
        response.setReqType(reqType);
        response.setTeam(team);
        response.setCity(cityBean.id);
        response.setIsSelf(isSelf);
        response.setCityStatus(cityBean.getStatus());
        response.setIsAttacker(isAttacker);
        response.setCampValue(cityBean.camp);
        response.addAllAttacker(cityBean.parseArmyBaseList(SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_ATK));
        response.addAllDefender(cityBean.parseArmyBaseList(SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_DEF));
        response.addAllAttackerStatus(cityBean.getArmyStatusCount(SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_ATK));
        response.addAllDefenderStatus(cityBean.getArmyStatusCount(SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_DEF));

        OccupyCityParam occupyCityParam = cityBean.getOccupyCityParam();
        if (occupyCityParam != null && occupyCityParam.getLoser() != null)
        {
            //有可能是不进行战斗的占领,这种情况没有loser
            SGCommonProto.MapBattleResult.Builder result = SGCommonProto.MapBattleResult.newBuilder();
            result.setAttacker(occupyCityParam.getWinner().parseBaseInfo());
            result.setDefender(occupyCityParam.getLoser().parseBaseInfo());
            result.setWinnerIndex(occupyCityParam.getWinner().getObjectIndex());
            response.setResultDroiyan(result);
            response.setTransitionCd((int) (occupyCityParam.getOccupyTime() + ConfigFactory.WORLD_MAP_STATUS_WAIT_TIME - DataFactory.currentTime));
        }

        if (showQueue) {
            List<SpriteBean> atkList = null, defList = null;
            if (team == SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_ATK) {
                atkList = cityBean.getSpriteBeanList(SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_ATK, reqType);
            } else if (team == SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_DEF) {
                defList = cityBean.getSpriteBeanList(SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_DEF, reqType);
            } else if (team == SGCommonProto.E_ARMY_TEAM.AMRY_TEAM_ALL) {
                atkList = cityBean.getSpriteBeanList(SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_ATK, reqType);
                defList = cityBean.getSpriteBeanList(SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_DEF, reqType);
            }

            if (atkList != null) {
                SGCommonProto.CityArmyQueue.Builder atkQueue = SGCommonProto.CityArmyQueue.newBuilder();
                for (SpriteBean spriteBean : atkList)
                {
                    atkQueue.addBaseInfo(spriteBean.parseBaseInfo());
                }
                response.setAtkQueue(atkQueue);
            }

            if (defList != null) {
                SGCommonProto.CityArmyQueue.Builder defQueue = SGCommonProto.CityArmyQueue.newBuilder();
                for (SpriteBean spriteBean : defList)
                {
                    defQueue.addBaseInfo(spriteBean.parseBaseInfo());
                }
                response.setDefQueue(defQueue);
            }
        }

        LogUtils.debug("通知的玩家数量 -> " + playerControllers.length  + "  notifyLookPlayer -> " + notifyLookPlayer + " cityDetailInfo -> " + response);

        byte[] data = response.build().toByteArray();
        for (Object o : playerControllers) {
            ((PlayerController) o).sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_CityDetailInfo_VALUE, data);
        }

        if (notifyLookPlayer) {
            //通知正在查看这个城的玩家
            cityBean.sendToLookPlayer(SGMainProto.E_MSG_ID.MsgID_WorldMap_CityDetailInfo_VALUE, data);
        }
    }

    /**
     * 通知药水使用次数
     * @param playerController
     * @param type
     * @param times
     */
    public static void sendWorldMapUserPropInfo(PlayerController playerController, int type, int times)
    {
        SGMapProto.S2C_WorldMapUseProp.Builder usePropBuilder = SGMapProto.S2C_WorldMapUseProp.newBuilder();
        usePropBuilder.setType(type);
        usePropBuilder.setUseTimes(times);
        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_UseProp_VALUE, usePropBuilder.build().toByteArray());
    }

    public static void sendWorldMapHPUpdate(PlayerController playerController, int change)
    {
        SGMapProto.S2C_HPUpdate.Builder response = SGMapProto.S2C_HPUpdate.newBuilder();
        response.setHpInfo(getHpPercent(playerController));
        response.setChange(change);
        playerController.sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_HpUpdate_VALUE, response.build().toByteArray());
    }

    public static void sendWorldMapHPUpdate(PlayerController playerController)
    {
        sendWorldMapHPUpdate(playerController, 0);
    }

    public static SGCommonProto.HpDetailInfo getHpPercent(PlayerController playerController)
    {
        Player player = playerController.getPlayer();
        WorldMapData worldMapData = WorldInfoFactory.getInstance().getWorldMapData(playerController);
        SpritePlayerBean spritePlayerBean = worldMapData != null ? worldMapData.getPlayerActionBean(playerController.getObjectIndex()) : null;

        SGCommonProto.HpDetailInfo.Builder builder =  SGCommonProto.HpDetailInfo.newBuilder();
        BattleTemp battleTemp = null;
        if(spritePlayerBean == null)
        {
            battleTemp = WorldInfoFactory.getInstance().getCacheBattleTemp(player.getObjectIndex());
        }
        else
        {
            battleTemp = spritePlayerBean.getBattleTemp();
        }

        if(battleTemp == null)
        {
            MasterConfig masterConfig = DataFactory.getInstance().getGameObject(DataFactory.MASTER_KEY, player.master);
            int hp = masterConfig.getAttribute(E_Attribute.HP.getCode(), player.getLv(), player.getMasterExtraAddAttributes(E_Attribute.HP.getCode()));
            builder.setMasterCurrentHp(hp);
            builder.setMasterTotalHp(hp);

            for(CardDB cardDB : player.getWorldMapCardList())
            {
                hp = cardDB.getAttribute(E_Attribute.HP.getCode());
                builder.setArmyCurrentHp(hp);
                builder.setArmyTotalHp(hp);
            }
        }
        else
        {
            LogUtils.debug("battleTemp -> " + battleTemp);
            builder.setMasterCurrentHp(battleTemp.getMaster().getHp());
            builder.setMasterTotalHp(battleTemp.getMaster().getMaxHp());
            builder.setArmyCurrentHp(battleTemp.getTotalArmyHP());
            builder.setArmyTotalHp(battleTemp.getTotalArmyMaxHP());
            builder.setArmyTotalHpByLive(battleTemp.getTotalArmyMaxHPByLive());
        }

        return builder.build();
    }

    public static void sendChangeQueue(CityBean cityBean, SGMapProto.S2C_ChangeQueue.Builder response, String... excludePlayerIndex)
    {
        if(response.getChangeObjectCount() == 0)
            return;

//        LogUtils.debug("changeList -> " + response);

        cityBean.dispatchMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_ChangeQueue_VALUE, response.build().toByteArray(), true, excludePlayerIndex);
    }

    public static void sendChangeQueue(CityBean cityBean, SGCommonProto.ArmyQueueChange queueChange, String... excludePlayerIndex)
    {
        sendChangeQueue(cityBean, SGMapProto.S2C_ChangeQueue.newBuilder().addChangeObject(queueChange), excludePlayerIndex);
    }

    public static void sendChangeQueue(CityBean cityBean, List<SGCommonProto.ArmyQueueChange> changeList)
    {
        sendChangeQueue(cityBean, SGMapProto.S2C_ChangeQueue.newBuilder().addAllChangeObject(changeList));
    }
    /**
     * 匹配组通知队列变化
     * @param cityBean
     * @param mapMatchTeam
     */
    public static void sendChangeQueue(CityBean cityBean, MapMatchTeam mapMatchTeam)
    {
        sendChangeQueue(cityBean, SGMapProto.S2C_ChangeQueue.newBuilder().addAllChangeObject(createChangeQueueList(mapMatchTeam)));
    }

    public static List<SGCommonProto.ArmyQueueChange> createChangeQueueList(MapMatchTeam mapMatchTeam)
    {
        List<SGCommonProto.ArmyQueueChange> result = new ArrayList<>();

        result.add(createChangeQueue(SGCommonProto.E_QUEUE_CHANGE.QUEUE_CHANGE_IN, SGCommonProto.E_ARMY_STATUS.ARMY_STATUS_BATTLE, SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_ATK, mapMatchTeam.getPlayer()));
        result.add(createChangeQueue(SGCommonProto.E_QUEUE_CHANGE.QUEUE_CHANGE_IN, SGCommonProto.E_ARMY_STATUS.ARMY_STATUS_BATTLE, SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_DEF, mapMatchTeam.getTarget()));
        result.add(createChangeQueue(SGCommonProto.E_QUEUE_CHANGE.QUEUE_CHANGE_OUT, SGCommonProto.E_ARMY_STATUS.ARMY_STATUS_MATCH, SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_ATK, mapMatchTeam.getPlayer()));
        result.add(createChangeQueue(SGCommonProto.E_QUEUE_CHANGE.QUEUE_CHANGE_OUT, SGCommonProto.E_ARMY_STATUS.ARMY_STATUS_MATCH, SGCommonProto.E_ARMY_TEAM.ARMY_TEAM_DEF, mapMatchTeam.getTarget()));

        return result;
    }


    public static SGCommonProto.ArmyQueueChange createChangeQueue(SGCommonProto.E_QUEUE_CHANGE changeType, SGCommonProto.E_ARMY_STATUS type, SGCommonProto.E_ARMY_TEAM team, SpriteBean spriteBean)
    {
        SGCommonProto.ArmyQueueChange.Builder data = SGCommonProto.ArmyQueueChange.newBuilder();
        data.setChangeType(changeType);
        data.setTeam(team);
        data.setType(type);
        data.setBaseInfo(spriteBean.parseBaseInfo());
        return data.build();
    }


    public static void sendMapChallenge(MapMatchTeam mapMatchTeam)
    {
        if (mapMatchTeam.getPlayer() instanceof SpritePlayerBean)
        {
            SGMapProto.S2C_CityMapChallenge.Builder response = null;

            SpritePlayerBean player = (SpritePlayerBean) mapMatchTeam.getPlayer();

            if (player.isCanSendMsg() && player.isInCity())
            {
                response = SGMapProto.S2C_CityMapChallenge.newBuilder();
                response.setTargetInfo(mapMatchTeam.getTarget().parseBaseInfo());
                response.setWaitTime(mapMatchTeam.getWaitTime());
                response.setTargetTeam(mapMatchTeam.getTarget().getTeam());
                player.sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_Challenge_VALUE, response.build().toByteArray());
            }

            if (mapMatchTeam.getTarget() instanceof SpritePlayerBean)
            {
                SpritePlayerBean target = (SpritePlayerBean) mapMatchTeam.getTarget();

                if (target.isCanSendMsg() && target.isInCity())
                {
                    response = SGMapProto.S2C_CityMapChallenge.newBuilder();
                    response.setTargetInfo(mapMatchTeam.getPlayer().parseBaseInfo());
                    response.setWaitTime(mapMatchTeam.getWaitTime());
                    response.setTargetTeam(mapMatchTeam.getPlayer().getTeam());
                    target.sendMsg(SGMainProto.E_MSG_ID.MsgID_WorldMap_Challenge_VALUE, response.build().toByteArray());
                }
            }
        }
    }
}
